import { ValidCode } from "../type";
//生成驗證碼+時間戳 存在Cache中

//隨機生成6位數字組成驗證碼

const ValidCodeGenerator = {
  apply(username: string): ValidCode {
    let Code =
      Math.round((Math.random() * 9)).toString() +
      Math.round((Math.random() * 9)).toString() +
      Math.round((Math.random() * 9)).toString() +
      Math.round((Math.random() * 9)).toString() +
      Math.round((Math.random() * 9)).toString() +
      Math.round((Math.random() * 9)).toString();
    let time = new Date().getTime();
    let validCode: ValidCode = {
      validCode: Code,
      timeRecord: time,
      userName: username,
    };
    return validCode;
  },
};

export { ValidCodeGenerator };
